package com.oos.zone.wechat.mp.service.handler;

import lombok.extern.log4j.Log4j2;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * 功能描述：订阅事件处理器
 *
 * @author 拓金辉
 * @version 1.0
 * @date 2021-08-08 10:52:36
 */
@Log4j2
@Service
public class WxMpSubscribeMessageHandler extends AbstractWxMpMessageHandler {

    @Override
    public WxMpXmlOutMessage handle0() {
        if (StringUtils.isBlank(wxMessage.getEvent())) {
            return defaultTextMessage;
        }
        switch (StringUtils.toRootLowerCase(wxMessage.getEvent())) {
            case "subscribe":
                return subscribe();
            case "unsubscribe":
                return unsubscribe();
            default:
                log.error("\n\n【事件类型未处理】\n\n {}", wxMessage.toString());
                return defaultTextMessage;
        }
    }

    public WxMpXmlOutMessage subscribe() {
        CompletableFuture.runAsync(() -> log.info("订阅事件"), executor);
        return defaultTextMessage;
    }

    public WxMpXmlOutMessage unsubscribe() {
        CompletableFuture.runAsync(() -> log.info("取消订阅事件"), executor);
        return defaultTextMessage;
    }

}